var id = $.query.get('id');
//document ready
$(function(){
	/*KindEditor.ready(function(K) {
		editor = K.create('textarea[name="text"]', {
			uploadJson : '/static/basic/plugins/kindeditor-4.1.1/jsp/upload_json.jsp',
            fileManagerJson : '/static/basic/plugins/kindeditor-4.1.1/jsp/file_manager_json.jsp',
            allowFileManager : true
		});
	});*/
	$('#saveButton').bind('click', save);//添加按钮绑定事件
	if(id){
		loadForm();
	}
});

function loadForm(){
	$.post("/security/ajax/map/select_get_${table_name}",JSON.stringify({id:id}),function(result){
		if(result.status==200){
			$('#form0').form('load',result.data);
		    //editor.html(result.data.text);
			//$('#editForm-logo_img').attr("src",result.data.logo);
		}else{
			$.messager.alert("提示", result.message);
		}
	});
}

function save(){
	var formObject=$("#form0").serializeObject();
	var url="/security/ajax/update/grid_${table_name}-insert";
	if(id){//修改
		url="/security/ajax/update/grid_${table_name}-update";
	}
	$.ajax({
		url: url,
		data:JSON.stringify(formObject),
		success: function(result){
			if(result.status==200){
				if(id){//修改
					$.messager.alert("提示", "更新成功！");
				}else{
					$.messager.alert("提示", "新增成功！");
					$("#form0").form('clear');
				}
			}else{
				$.messager.alert("提示", "保存失败！");
			}
		},
		error: function(){
			$.messager.alert("提示", "服务器响应异常！");
		}
	});
}
